﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HomeWork5
{
    class Program
    {
        static void Main(string[] args)
        {
            Program a = new Program();
            a.calculate1();
            Console.WriteLine(" ");
            a.calculate2();
        }
        private void calculate1()
        {
            List<int> myInts = new List<int>();
            int _bottom = 2;
            int _top = 98;
            for (int i = _bottom; i < _top; i++)
            {
                bool isPrimeNumber = true;
                for (int j = 2; j < i; j++)
                {
                    if (i % j == 0)
                    {
                        isPrimeNumber = false;
                    }
                }
                if (isPrimeNumber == true)
                {
                    myInts.Add(i);
                }
            }
            for (int i = 8; i <= 98; i = i + 2) {
                foreach (int n in myInts) {
                    int difference = i - n;
                    if (n <= difference)
                    {
                        var result = from element in myInts where element == difference select element;
                        foreach (var m in result)
                        {
                            if (m == difference)
                            {
                                Console.WriteLine(i + "=" + n + "+" + difference);
                            }
                        }
                    }
                }
            }
        }
        private void calculate2() {
            Random rando = new Random();
            List<int> myInts = new List<int>();
            for (int i = 0; i <= 100; i++)
            {
                int j=rando.Next(1001);
                myInts.Add(j);
            }
            var afterlinq = from n in myInts orderby n descending select n;
            var sum = myInts.Sum();
            var average = myInts.Average();
            foreach (int n in afterlinq) {
                Console.Write(n+"  ");
            }
            Console.WriteLine(" ");
            Console.WriteLine("平均数为"+average);
            Console.WriteLine("求和为" + sum);
        }

    }

}

